// GPRS
var PageGprs = {
    id: "PageGprs", //页面id
    menu: "i18n.lan.menu.dataTrans", //所属菜单(一级菜单名)
    title: "i18n.lan.menu.PageGprs", //标题（二级菜单名）
    parentIcon: "icon-me-gprs", //一级菜单图标
    icon: "icon-me-gprs", //图标
    refreshBtnCmd: "DUMP_CORE", //刷新按钮指令
    saveBtn: true, //保存按钮
    el: [ //控件
        {//css定义
            elname:"style",
            text:"#PageGprs > label{min-width:160px;} #PageGprs #btnSetGprsDftSvr{margin-left: 540px;padding:0px 8px;}",
        },
        {
            elname: "checkbox",
            label: i18n.lan.PageGprs.dtu0Gprs,
            id: "gprs_dtu0Gprs",
            endRow: true,
            attrs: {
                dumpKey: "DTU0_GPRS",
                cmdKey: "DTU0GPRS",
            }
        },
        {
            elname: "text",
            label: i18n.lan.PageGprs.deviceId,
            endRow: true,
            attrs: {
                dumpKey: "CWTIOID",
                cmdKey: "CWTIOID",
            }
        },
        {
            elname: "text",
            label: i18n.lan.PageGprs.uploadTimer,
            endRow: true,
            attrs: {
                dumpKey: "IOTTO",
                cmdKey: "IOTTO",
            }
        },

        {
            elname: "text",
            label: i18n.lan.PageGprs.httpPostUrl,
            // endRow: true,
            attrs: {
                dumpKey: "HTTPPOSTURL",
                cmdKey: "HTTPPOSTURL",
            }
        },
        {//设置默认服务器按钮
            elname:"button",
            text:i18n.lan.PageGprs.setDefaultSvr,
            endRow:true,
            attrs:{
                id:"btnSetGprsDftSvr",
                onclick:"setDefaultGprsSvr()",
            }
        },
        {
            elname: "datagrid",
            rowCount: Device.getNodesCount("gprs"), //必选,行数
            data: {
                width:1050,
                columns: [
                    [{
                            field: "index",
                            width: 40,
                            align: "center",
                        },
                        {
                            field: "serverAddress",
                            editor: Easyui.editor.textbox,
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 0,
                            cmdKey: "IOTSVR<n>,", //注意逗号
                            otherFields: "serverPort,transType,transProtocol", //其它的参数的field
                            width: 200,
                        },
                        {
                            field: "serverPort",
                            editor: Easyui.editor.numberbox,
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 1,
                            width: 80,
                        },
                        {
                            field: "transType",
                            formatter: Easyui.formatter.combobox,
                            editor: new Easyui.editor.Combobox(Device.getTransTypeItemsKV()),
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 2,
                            width: 120,
                        },
                        {
                            field: "transProtocol",
                            formatter: Easyui.formatter.combobox,
                            editor: new Easyui.editor.Combobox(Device.getTransProtocolItemsKV()),
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 3,
                            width: 150,
                        },
                        {
                            field: "heartTime",
                            editor: Easyui.editor.numberbox,
                            dumpKey: "IOTHEART<n>",
                            dumpParamIndex: 2,
                            width: 80,
                        },
                        {
                            field: "heartPacket",
                            editor: Easyui.editor.textbox,
                            dumpKey: "IOTHEART<n>",
                            dumpParamIndex: 0,
                            cmdKey: "IOTHEART<n>,", //注意逗号
                            otherFields: "heartFormat,heartTime",
                            width: 120,
                        },
                        {
                            field: "heartFormat",
                            formatter: Easyui.formatter.combobox,
                            editor: new Easyui.editor.Combobox(i18n.lan.PageGprs.heartFormatItemsKV),
                            dumpKey: "IOTHEART<n>",
                            dumpParamIndex: 1,
                            width: 120,
                        },
                        {
                            field: "registPacket",
                            editor: Easyui.editor.textbox,
                            dumpKey: "IOTREGIST<n>",
                            dumpParamIndex: 0,
                            cmdKey: "IOTREGIST<n>,", //注意逗号
                            width: 120,
                        },
                    ]
                ],
            },
        }
    ],
}
CmdPage.add(PageGprs); //添加到页面管理

// 设置默认GPRS服务器
function setDefaultGprsSvr(){
    if(PageGprs.dgData.rows.length==0) return;
    let dgId = "PageGprs_dg";
    let row = $("#"+dgId).datagrid("getSelected");
    if(!row) row = PageGprs.dgData.rows[0];
    //修改数据
    row.serverAddress = i18n.lan.PageGprs.defaultGprsServer;
    row.serverPort = 8082;
    row.transType = 0;
    row.transProtocol = 0;
    row.heartTime = 900;
    row.heartFormat = 1;//字符格式
    //更新显示
    DatagridTool.updateData(dgId,true);
    //标记为修改
    DatagridTool.addToUpdatedRows(dgId,row);
}